package com.itheima.tanhua.dto;

import com.itheima.tanhua.mongo.UserLocation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;

import java.io.Serializable;

/**
 * @author Lff
 * @date 2022/4/1
 * <p>
 * 地理位置信息传输
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LocationDto implements Serializable {

    private Long userId;//当前操作用户id
    private Double latitude;//纬度
    private Double longitude;//经度
    private String addrStr;//位置描述


    /**
     * 转变成UserLocation
     *
     * @return
     */
    public UserLocation toUserLocation() {
        UserLocation userLocation = new UserLocation();
        userLocation.setUserId(this.userId);
        //创建时间
        userLocation.setCreated(System.currentTimeMillis());
        //修改时间
        userLocation.setUpdated(System.currentTimeMillis());
        //最后修改时间
        userLocation.setLastUpdated(System.currentTimeMillis());
        //地理位置描述
        userLocation.setAddress(this.addrStr);
        userLocation.setLocation(new GeoJsonPoint(this.longitude, this.latitude));
        return userLocation;
    }

    public GeoJsonPoint toGeoJsonPoint() {
        return new GeoJsonPoint(this.longitude, this.latitude);
    }
}
